#include"chen.h"

static void connect_alarm( int );


int
connect_timeo( int sockfd, const struct sockaddr *servaddr, socklen_t servlen, int nsec )
{
	sig_t sigfunc;
	int n;

	sigfunc = signal( SIGALRM, connect_alarm );

	if ( alarm( nsec ) != 0 ) 
		err_msg( "connect_timeo:alarm was already set" );

	if ( ( n = connect( sockfd, servaddr, servlen ) ) < 0 ) {
		close( sockfd );
		if ( errno == EINTR )
			errno = ETIMEDOUT;
	}
	alarm( 0 );

	signal( SIGALRM, sigfunc );

	return n;
}

static void
connect_alarm( int signo )
{
	return;
}
